<?php

class DkpRecalculatePlugin extends Zend_Controller_Plugin_Abstract
{
	private $registryName = "characters_needing_update";

	public function __construct()
    {
    	// Make sure that the character array is preset in the database
    	Zend_Registry::getInstance()->set($this->registryName, array());
    }
	
    
    public function dispatchLoopShutdown()
    {
    	// This array will is setup in the following way:
    	// 		characterId => timeToUpdateFrom
    	// So, only one entry per character needing update
		$characters = Zend_Registry::getInstance()->get($this->registryName);
		
		// No update needed
		if (empty($characters)) return;
		
		$dkpUpdater = new DkpUpdater();
		
		foreach($characters as $id => $time){
			$dkpUpdater->normalizeUser($id,$time);
		}
		
		/*
		echo "DKP update needed for following characters:<br/>";
		
		echo "<ul>";
		foreach($characters as $character=>$time) {
			echo "<li> " . $time . " @ " . $character . "</li>";
		}
		echo "</ul>";
        */
		
    }
}